﻿<%@ Page Title="Skupina uživatelů" Language="C#" MasterPageFile="~/Pages/Site.Master" AutoEventWireup="true" CodeBehind="Detail.aspx.cs" Inherits="Altairis.FluffyCloud.WebCore.Pages.Groups.Detail" %>
<asp:Content ContentPlaceHolderID="Main" runat="server">
    <asp:FormView ID="FormView" runat="server" ItemType="Altairis.FluffyCloud.Data.Role" DataKeyNames="RoleName" SelectMethod="FormView_GetItem" InsertMethod="FormView_InsertItem" UpdateMethod="FormView_UpdateItem" DeleteMethod="FormView_DeleteItem">
        <ItemTemplate>
            <h1><%#: string.Format("Skupina '{0}'", Item.RoleName) %></h1>
            <p><%#: Item.Description %></p>
            <p>Tato skupina je systémová nebo nejste jejím vlastníkem. Proto ji nemůžete editovat.</p>
            <asp:ListView ID="UserList" runat="server" ItemType="Altairis.FluffyCloud.Data.User" SelectMethod="UserList_GetData">
                <EmptyDataTemplate>
                    <p>Tato skupina je prázdná.</p>
                </EmptyDataTemplate>
                <LayoutTemplate>
                    <table class="grid">
                        <tbody>
                            <asp:PlaceHolder ID="ItemPlaceHolder" runat="server" />
                        </tbody>
                    </table>
                </LayoutTemplate>
                <ItemTemplate>
                    <tr>
                        <td style="width: 40px">
                            <my:UserIcon runat="server" UserName="<%# Item.UserName %>" Size="40" NavigateUrl='<%# this.GetRouteUrl("UserProfile", new { username = Item.UserName }) %>' />
                        </td>
                        <td>
                            <a href='<%# this.GetRouteUrl("UserProfile", new { username = Item.UserName }) %>' class="strong"><%#: Item.UserName.ToUpper() %></a>
                            <%#: string.Format("({0})", Item.Species) %><br />
                            <%#: Item.Comment %>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:ListView>
        </ItemTemplate>
        <EditItemTemplate>
            <h1><%#: string.Format("Editace skupiny '{0}'", Item.RoleName) %></h1>
            <div class="form">
                <div>
                    <asp:Label runat="server" Text="Popis:" AssociatedControlID="DescriptionTextBox" />
                    <br />
                    <asp:TextBox ID="DescriptionTextBox" runat="server" MaxLength="50" Text="<%# BindItem.Description %>" />
                    <asp:RequiredFieldValidator runat="server" ControlToValidate="DescriptionTextBox" Display="None" ErrorMessage="Není zadán popis" />
                </div>
                <asp:ValidationSummary runat="server" />
                <div>
                    <asp:Button Text="Smazat" runat="server" CommandName="Delete" CausesValidation="false" data-confirm-prompt="Opravdu chcete tuto skupinu nevratně smazat?" Style="float: right" />
                    <asp:Button Text="Uložit" runat="server" CommandName="Update" />
                </div>
            </div>
            <h2>Členové skupiny</h2>
            <asp:ListView ID="UserList" runat="server" InsertItemPosition="FirstItem" ItemType="Altairis.FluffyCloud.Data.User" DataKeyNames="UserName" SelectMethod="UserList_GetData" InsertMethod="UserList_InsertItem" DeleteMethod="UserList_DeleteItem">
                <LayoutTemplate>
                    <table class="grid">
                        <thead>
                            <tr>
                                <td></td>
                                <td>Nick</td>
                                <td>Popis</td>
                                <td>Druh</td>
                                <td></td>
                            </tr>
                        </thead>
                        <tbody>
                            <asp:PlaceHolder ID="ItemPlaceHolder" runat="server" />
                        </tbody>
                    </table>
                </LayoutTemplate>
                <InsertItemTemplate>
                    <tr class="insert">
                        <td colspan="4">
                            <asp:DropDownList ID="AddUserList" runat="server" SelectMethod="AddUserList_GetData" DataTextField="Text" DataValueField="Value" SelectedValue="<%# BindItem.UserName %>" />
                        </td>
                        <td class="btn">
                            <altairis:IconLinkButton runat="server" Icon="Add" AlternateText="Přidat" CommandName="Insert" />
                        </td>
                    </tr>
                </InsertItemTemplate>
                <ItemTemplate>
                    <tr>
                        <td style="width: 40px">
                            <my:UserIcon runat="server" UserName="<%# Item.UserName %>" Size="40" NavigateUrl='<%# this.GetRouteUrl("UserProfile", new { username = Item.UserName }) %>' />
                        </td>
                        <td><%#: Item.UserName %></td>
                        <td><%#: Item.Comment %></td>
                        <td><%#: Item.Species %></td>
                        <td class="btn">
                            <altairis:IconLinkButton runat="server" Icon="Delete" AlternateText="Smazat" CommandName="Delete" />
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:ListView>
        </EditItemTemplate>
        <InsertItemTemplate>
            <h1>Nová skupina</h1>
            <div class="form">
                <div>
                    <asp:Label runat="server" Text="Název skupiny:" AssociatedControlID="RoleNameTextBox" />
                    <br />
                    <asp:TextBox ID="RoleNameTextBox" runat="server" MaxLength="50" Text="<%# BindItem.RoleName %>" />
                    <asp:RequiredFieldValidator runat="server" ControlToValidate="RoleNameTextBox" Display="None" ErrorMessage="Není zadán název skupiny" />
                    <asp:RegularExpressionValidator ErrorMessage="Název skupiny obsahuje nepovolené znaky" ControlToValidate="RoleNameTextBox" runat="server" Display="None" ValidationExpression="[A-Za-z0-9]+" />
                    <aside>Název skupiny smí obsahovat pouze písmena A-Z a číslice.</aside>
                </div>
                <div>
                    <asp:Label runat="server" Text="Popis:" AssociatedControlID="DescriptionTextBox" />
                    <br />
                    <asp:TextBox ID="DescriptionTextBox" runat="server" MaxLength="50" Text="<%# BindItem.Description %>" />
                    <asp:RequiredFieldValidator runat="server" ControlToValidate="DescriptionTextBox" Display="None" ErrorMessage="Není zadán popis" />
                </div>
                <asp:ValidationSummary runat="server" />
                <div>
                    <asp:Button Text="Odeslat" runat="server" CommandName="Insert" />
                </div>
            </div>
        </InsertItemTemplate>
    </asp:FormView>
</asp:Content>